{
 "cells": [
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "'''\n",
    "LCP 17. 速算机器人\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 1 << len(s)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    str1 = \"AB\"\n",
    "    sl = Solution()\n",
    "    print(sl.calculate(str1))"
   ],
   "id": "cb4d5db9df180c35",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "\n",
    "'''\n",
    "3248. 矩阵中的蛇\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def finalPositionOfSnake(self, n: int, commands: List[str]) -> int:\n",
    "        position = 0\n",
    "        if not commands:\n",
    "            return 0\n",
    "\n",
    "        for i in range(len(commands)):\n",
    "            if commands[i] == \"UP\":\n",
    "                position -= n\n",
    "            elif commands[i] == \"DOWN\":\n",
    "                position += n\n",
    "            elif commands[i] == \"LEFT\":\n",
    "                position -= 1\n",
    "            else:\n",
    "                position += 1\n",
    "\n",
    "        return position\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    n = 2\n",
    "    commands = [\"RIGHT\", \"DOWN\"]\n",
    "    sl = Solution()\n",
    "    print(sl.finalPositionOfSnake(n, commands))"
   ],
   "id": "d1a2e15f7c322bce",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "'''\n",
    "LCR 120. 寻找文件副本\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def findRepeatDocument(self, documents: List[int]) -> int:\n",
    "        dp = set()\n",
    "        for i in documents:\n",
    "            if i in dp:\n",
    "                return i\n",
    "            dp.add(i)\n",
    "        return -1\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    documents = [2, 5, 3, 0, 5, 0]\n",
    "    sl = Solution()\n",
    "    print(sl.findRepeatDocument(documents))"
   ],
   "id": "e2937dad55743eb8",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "'''\n",
    "LCR 002. 二进制求和\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def addBinary(self, a: str, b: str) -> str:\n",
    "        carry = 0\n",
    "        i, j = len(a) - 1, len(b) - 1\n",
    "        res = []\n",
    "        while i >= 0 or j >= 0 or carry > 0:\n",
    "            bin_a = int(a[i]) if i >= 0 else 0\n",
    "            bin_b = int(b[j]) if j >= 0 else 0\n",
    "            temp = bin_a + bin_b + carry\n",
    "            res.append(str(temp % 2))\n",
    "            carry = temp // 2\n",
    "\n",
    "            i -= 1\n",
    "            j -= 1\n",
    "        return \"\".join(res[::-1])\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    a = \"11\"\n",
    "    b = \"10\"\n",
    "    sl = Solution()\n",
    "    print(sl.addBinary(a, b))"
   ],
   "id": "b9bed96d257049a3",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "'''\n",
    "面试题 01.01. 判定字符是否唯一\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        if astr is None:\n",
    "            return True\n",
    "\n",
    "        str_len = len(astr)\n",
    "        if str_len == 1:\n",
    "            return True\n",
    "\n",
    "        astr = sorted(astr)\n",
    "        for i in range(1, str_len):\n",
    "            if astr[i] == astr[i - 1]:\n",
    "                return False\n",
    "        return True\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    s = \"abcc\"\n",
    "    sl = Solution()\n",
    "    print(sl.isUnique(s))"
   ],
   "id": "e3f65f413b4e1ec3",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import Optional\n",
    "\n",
    "'''\n",
    "LCR 144. 翻转二叉树\n",
    "'''\n",
    "\n",
    "\n",
    "class TreeNode:\n",
    "    def __init__(self, val=0, left=None, right=None):\n",
    "        self.val = val\n",
    "        self.left = left\n",
    "        self.right = right\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def flipTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:\n",
    "        if root is None:\n",
    "            return None\n",
    "\n",
    "        stack = [root]\n",
    "        while stack:\n",
    "            node = stack.pop()\n",
    "            if node.left: stack.append(node.left)\n",
    "            if node.right: stack.append(node.right)\n",
    "            node.left, node.right = node.right, node.left\n",
    "        return root\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    root = TreeNode(1, TreeNode(2), TreeNode(3))\n",
    "    sl = Solution()\n",
    "    print(sl.flipTree(root))"
   ],
   "id": "b3a5ee4f68d889b7",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "\n",
    "'''\n",
    "LCR 173. 点名\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def takeAttendance(self, records: List[int]) -> int:\n",
    "        left, right = 0, len(records) - 1\n",
    "        while left <= right:\n",
    "            mid = (left + right) // 2\n",
    "            if records[mid] != mid:\n",
    "                right = mid - 1\n",
    "            else:\n",
    "                left = mid + 1\n",
    "        return left\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    records = [0, 1, 2, 3, 5]\n",
    "    sl = Solution()\n",
    "    print(sl.takeAttendance(records))"
   ],
   "id": "b8a9b17ca37cfd2b",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "'''\n",
    "3349. 检测相邻递增子数组 I\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def hasIncreasingSubarrays(self, nums: List[int], k: int) -> bool:\n",
    "        num_len = len(nums)\n",
    "        if num_len < k * 2:\n",
    "            return False\n",
    "\n",
    "        if k == 1:\n",
    "            return True\n",
    "\n",
    "        count = 0\n",
    "        for i in range(num_len - 1, -1, -1):\n",
    "            if nums[i] - nums[i - k + 1] == k - 1:\n",
    "                for j in range(i, i - k, -1):\n",
    "                    if nums[i] - nums[i - 1] != 1:\n",
    "                        return False\n",
    "                count += 1\n",
    "        return count == 2\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    nums = [-15, 19]\n",
    "    k = 1\n",
    "    sl = Solution()\n",
    "    print(sl.hasIncreasingSubarrays(nums, k))"
   ],
   "id": "9a3c9d98c3190ab9",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "\n",
    "'''\n",
    "1480. 一维数组的动态和\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def runningSum(self, nums: List[int]) -> List[int]:\n",
    "        n_len = len(nums)\n",
    "\n",
    "        if n_len == 0:\n",
    "            return [0]\n",
    "        if n_len == 1:\n",
    "            return nums\n",
    "\n",
    "        lower, fast = 0, 1\n",
    "        while fast < n_len:\n",
    "            nums[fast] += nums[lower]\n",
    "            lower += 1\n",
    "            fast += 1\n",
    "        return nums\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    nums = [1, 2, 3, 4]\n",
    "    sl = Solution()\n",
    "    print(sl.runningSum(nums))"
   ],
   "id": "6d466a3a5aeaebfa",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "\n",
    "'''\n",
    "1408. 数组中的字符串匹配\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def stringMatching(self, words: List[str]) -> List[str]:\n",
    "        l_len = len(words)\n",
    "        if l_len <= 1:\n",
    "            return []\n",
    "\n",
    "        res = []\n",
    "        for i in range(l_len):\n",
    "            for j in range(i + 1, l_len):\n",
    "                if words[i] in words[j]:\n",
    "                    if words[i] not in res:\n",
    "                        res.append(words[i])\n",
    "                elif words[j] in words[i]:\n",
    "                    if words[j] not in res:\n",
    "                        res.append(words[j])\n",
    "        return res\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    words = [\"mass\", \"as\", \"hero\", \"superhero\"]\n",
    "    sl = Solution()\n",
    "    print(sl.stringMatching(words))"
   ],
   "id": "f7f979dfb34d1fa1",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "\n",
    "'''\n",
    "1431. 拥有最多糖果的孩子\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        c_max = max(candies)\n",
    "        return [i + extraCandies >= c_max for i in candies]\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    candies = [2]\n",
    "    extraCandies = 3\n",
    "    sl = Solution()\n",
    "    print(sl.kidsWithCandies(candies, extraCandies))"
   ],
   "id": "f21b0c1ac36978d4",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "'''\n",
    "1518. 换水问题\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def numWaterBottles(self, numBottles: int, numExchange: int) -> int:\n",
    "        bottles = drink = numBottles\n",
    "        while numBottles:\n",
    "            numBottles = bottles // numExchange\n",
    "            drink += numBottles\n",
    "            bottles = numBottles + (bottles % numExchange)\n",
    "        return drink\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    numBottles = 15\n",
    "    numExchange = 4\n",
    "    sl = Solution()\n",
    "    print(sl.numWaterBottles(numBottles, numExchange))"
   ],
   "id": "2ed81658c84b2004",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "\n",
    "'''\n",
    "1450. 在既定时间做作业的学生人数\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        # count = 0\n",
    "        # for i in range(len(startTime)):\n",
    "        #     if startTime[i] <= queryTime <= endTime[i]:\n",
    "        #         count += 1\n",
    "        # return count\n",
    "\n",
    "        return sum(s <= queryTime <= e for s, e in zip(startTime, endTime))\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    startTime = [1, 2, 3]\n",
    "    endTime = [3, 2, 7]\n",
    "    queryTime = 4\n",
    "    sl = Solution()\n",
    "    print(sl.busyStudent(startTime, endTime, queryTime))"
   ],
   "id": "1a8f95d7f01e2a11",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "import bisect\n",
    "from typing import List\n",
    "\n",
    "'''\n",
    "1385. 两个数组间的距离值\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def findTheDistanceValue(self, arr1: List[int], arr2: List[int], d: int) -> int:\n",
    "        arr2.sort()\n",
    "        cnt = 0\n",
    "        for x in arr1:\n",
    "            p = bisect.bisect_left(arr2, x)\n",
    "            if p == len(arr2) or abs(x - arr2[p]) > d:\n",
    "                if p == 0 or abs(x - arr2[p - 1]) > d:\n",
    "                    cnt += 1\n",
    "        return cnt\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    arr1 = [4, 5, 8]\n",
    "    arr2 = [10, 9, 1, 8]\n",
    "    d = 2\n",
    "    sl = Solution()\n",
    "    print(sl.findTheDistanceValue(arr1, arr2, d))"
   ],
   "id": "91920a6a09f5a122",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "'''\n",
    "1446. 连续字符\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def maxPower(self, s: str) -> int:\n",
    "        pass\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    s = \"leetcode\"\n",
    "    sl = Solution()\n",
    "    print(sl.maxPower(s))"
   ],
   "id": "a31849dc212d9595",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "'''\n",
    "现在给定一个长度为n的数组 nums，请找到峰值并返回其索引。\n",
    "数组可能包含多个峰值，在这种情况下，返回任何一个所在位置即可。\n",
    "比如输入数组[2,4,1,2,7,8,4]时，会形成两个山峰，一个是索引为1，峰值为4的山峰，另一个是索引为5，峰值为8的山峰.\n",
    "'''\n",
    "\n",
    "\n",
    "def search(nums: list):\n",
    "    res = []\n",
    "    nums_len = len(nums)\n",
    "    if nums_len == 1:\n",
    "        return nums\n",
    "    if nums_len > 1:\n",
    "        if nums[0] > nums[1]:\n",
    "            res.append(0)\n",
    "        if nums[-1] > nums[-2]:\n",
    "            res.append(nums_len - 1)\n",
    "    for i in range(1, nums_len - 1):\n",
    "        if nums[i] > nums[i - 1]:\n",
    "            if nums[i] > nums[i + 1]:\n",
    "                res.append(i)\n",
    "    return res\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    print(search([6, 4, 7, 2, 7, 8, 4]))"
   ],
   "id": "f0c744b8106a982e",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "\n",
    "'''\n",
    "LCR 181. 字符串中的单词反转\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def reverseMessage(self, message: str) -> str:\n",
    "        # msg = message.strip().split(' ')\n",
    "        # msg.reverse()\n",
    "        # msg = [msg[i] for i in range(len(msg)) if msg[i] != '']        \n",
    "        # return ' '.join(msg)\n",
    "\n",
    "        message = message.strip()\n",
    "        i = j = len(message) - 1\n",
    "        res = []\n",
    "        while i >= 0:\n",
    "            while i >= 0 and message[i] != ' ': i -= 1\n",
    "            res.append(message[i + 1: j + 1])\n",
    "            while i >= 0 and message[i] == ' ': i -= 1\n",
    "            j = i\n",
    "        return ' '.join(res)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    message = \"  hello world!  \"\n",
    "    sl = Solution()\n",
    "    print(sl.reverseMessage(message))"
   ],
   "id": "13fbbc67983e483f",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "\n",
    "'''\n",
    "3206. 交替组 I\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def numberOfAlternatingGroups(self, colors: List[int]) -> int:\n",
    "        res = 0\n",
    "        c_len = len(colors)\n",
    "        for i in range(c_len):\n",
    "            if i == 0:\n",
    "                if colors[-1] != colors[i] and colors[i] != colors[i + 1]:\n",
    "                    res += 1\n",
    "            elif i == c_len - 1:\n",
    "                if colors[i - 1] != colors[i] and colors[i] != colors[0]:\n",
    "                    res += 1\n",
    "            else:\n",
    "                if colors[i - 1] != colors[i] and colors[i] != colors[i + 1]:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    colors = [0, 1, 0, 0, 1]\n",
    "    sl = Solution()\n",
    "    print(sl.numberOfAlternatingGroups(colors))"
   ],
   "id": "237daab5347ba9e",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "\n",
    "'''\n",
    "3151. 特殊数组 I\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def isArraySpecial(self, nums: List[int]) -> bool:\n",
    "        if len(nums) <= 1:\n",
    "            return True\n",
    "\n",
    "        for i in range(len(nums) - 1):\n",
    "            if (nums[i] + nums[i + 1]) % 2 == 0:\n",
    "                return False\n",
    "        return True\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    nums = [4, 2, 2, 1]\n",
    "    sl = Solution()\n",
    "    print(sl.isArraySpecial(nums))"
   ],
   "id": "ec50ed46b7fa83c7",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import Optional\n",
    "\n",
    "'''\n",
    "面试题 02.01. 移除重复节点\n",
    "'''\n",
    "\n",
    "\n",
    "# Definition for singly-linked list.\n",
    "class ListNode:\n",
    "    def __init__(self, val=0, next=None):\n",
    "        self.val = val\n",
    "        self.next = next\n",
    "\n",
    "    def __repr__(self):\n",
    "        return f'{self.val} -> {self.next}'\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def removeDuplicateNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:\n",
    "        if not head:\n",
    "            return None\n",
    "        seen = set()\n",
    "        current = head\n",
    "        seen.add(current.val)\n",
    "        while current.next:\n",
    "            if current.next.val in seen:\n",
    "                current.next = current.next.next\n",
    "            else:\n",
    "                seen.add(current.next.val)\n",
    "                current = current.next\n",
    "        return head\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    head = ListNode(1, ListNode(2, ListNode(3, ListNode(3, ListNode(2, ListNode(1))))))\n",
    "    sl = Solution()\n",
    "    # print(head)\n",
    "    print(sl.removeDuplicateNodes(head))"
   ],
   "id": "9cedc8a9a49ff0f2",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "'''\n",
    "1446. 连续字符\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def maxPower(self, s: str) -> int:\n",
    "        res = count = 1\n",
    "        for i in range(1, len(s)):\n",
    "            if s[i] == s[i - 1]:\n",
    "                count += 1\n",
    "                res = max(count, res)\n",
    "            else:\n",
    "                count = 1\n",
    "        return res\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    s = \"aabbbbbccccdddddddeffffffggghhhhhiiiiijjjkkkkkllllmmmmmnnnnnoopppqrrrrsssttttuuuuvvvvwwwwwwwxxxxxyyyzzzzzzzz\"\n",
    "    sl = Solution()\n",
    "    print(sl.maxPower(s))"
   ],
   "id": "620d6f177a4967b",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "\n",
    "'''\n",
    "1475. 商品折扣后的最终价格\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def finalPrices(self, prices: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(len(prices)):\n",
    "            for j in range(i + 1, len(prices)):\n",
    "                temp = prices[i] - prices[j]\n",
    "                if temp >= 0:\n",
    "                    res.append(temp)\n",
    "                    break\n",
    "            else:\n",
    "                res.append(prices[i])\n",
    "        return res\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    prices = [10, 1, 1, 6]\n",
    "    sl = Solution()\n",
    "    print(sl.finalPrices(prices))"
   ],
   "id": "cf75a34207a3e43f",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "'''\n",
    "1356. 根据数字二进制下 1 的数目排序\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def sortByBits(self, arr: List[int]) -> List[int]:\n",
    "        pass\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    arr = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]\n",
    "    sl = Solution()\n",
    "    print(sl.sortByBits(arr))"
   ],
   "id": "acc9a1fa46b599e6",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "\n",
    "'''\n",
    "2643. 一最多的行\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        max_sum, idx = -1, 0\n",
    "        for i, row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if max_sum < s:\n",
    "                max_sum, idx = s, i\n",
    "        return [idx, max_sum]\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    mat = [[0, 0, 0], [0, 1, 1]]\n",
    "    sl = Solution()\n",
    "    print(sl.rowAndMaximumOnes(mat))"
   ],
   "id": "c31944733776459",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "\n",
    "'''\n",
    "2540. 最小公共值\n",
    "'''\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def getCommon(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        s1, s2 = set(nums1), set(nums2)\n",
    "        p = s1 & s2\n",
    "        return min(p) if p else -1\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    nums1 = [1, 2, 3]\n",
    "    nums2 = [4, 5]\n",
    "    sl = Solution()\n",
    "    print(sl.getCommon(nums1, nums2))"
   ],
   "id": "512b674895af02cd",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from typing import List\n",
    "'''\n",
    "2506. 统计相似字符串对的数目\n",
    "'''\n",
    "\n",
    "class Solution:\n",
    "    def similarPairs(self, words: List[str]) -> int:\n",
    "        pass\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    words = [\"aba\",\"aabb\",\"abcd\",\"bac\",\"aabc\"]\n",
    "    sl = Solution()\n",
    "    print(sl.similarPairs(words))"
   ],
   "id": "dc432e0968f0d2f3",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
